<template>
  <a-modal
    title="打印"
    :width="900"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @cancel="handleCancel"
  >
  <template slot="footer">
        <a-button key="back" @click="handleCancel">
          取消
        </a-button>
        <a-button key="submit" type="primary"  @click="handleSubmit">
          打印
        </a-button>
  </template>
  <div class="print"  ref="print">
    <a-row>
      <a-col :span="24" class="title">
       <strong>{{ form.letterhead }}</strong>
      </a-col>
    </a-row>
    <a-row>
      <a-col :span="24" class="title">
       <strong v-if="data.type === 1">收入</strong>
       <strong v-if="data.type === 2">支出</strong>
       <strong v-if="data.type === 3">應收帳</strong>
       <strong v-if="data.type === 4">應付帳</strong>
      </a-col>
    </a-row>
    <a-row>
      <a-col :span="12" class="ydxx">
       <span>住戶：{{ data.roomName }} - {{ data.name }}</span>
      </a-col>
      <a-col :span="12" class="ydxx">
       <span class="item-end">收租日：{{ data.shouldReceiveDate }}</span>
      </a-col>
    </a-row>
    <div class="main-content">
      <a-row class="dj main-content-item">
        <a-col :span="24" class="ydxx">
          <span>{{ data.revenuesTypeName }}：{{ data.amount }}元</span>
        </a-col>
      </a-row>
      <a-row class="main-content-item">
        <a-col :span="24" class="ydxx">
          <h3>小計：{{ data.amount }}元</h3>
        </a-col>
      </a-row>
    </div>
      <a-row>
      <a-col :span="8" class="ydxx">
       <span>打印日期：{{ dayinDate }}</span>
      </a-col>
      <a-col :span="8" class="ydxx">
       <span>付款人：</span>
      </a-col>
      <a-col :span="8" class="ydxx">
       <span class="item-end">收款人：{{ form.payee }}</span>
      </a-col>
    </a-row>
  </div>
  </a-modal>
</template>

<script>
  import { busPrintSettingsOne } from '@/api/modular/main/busprintsettings/busPrintSettingsManage'
  import { getLookDetail } from '@/api/modular/main/billotherrevenues/billOtherRevenuesManage'
  import moment from 'moment'
  export default {
    data () {
      return {
        visible: false,
        confirmLoading: false,
        roomCode: '',
        ydNo: '',
        reservation: '',
        collectionDate: '',
        deposit: '',
        rent: '',
        receiptCycle: '',
        latestDate: '',
        dayinDate: moment().format('YYYY-MM-DD'),
        remark: '',
        data: {},
        form: {
          id: '',
          size: '',
          letterhead: '',
          letterheadenable: true,
          customerenable: true,
          titleenable: true,
          payerenable: true,
          payer: '',
          payeeenable: true,
          payee: '',
          remark: ''
        }
      }
    },
    created() {
      this.getData()
    },
    methods: {
      moment,
      // 初始化方法
      edit (id) {
        this.visible = true
        this.getTreDat(id)
      },
      getTreDat(id) {
        getLookDetail(id).then((res) => {
          if (res.code === 200) {
            this.data = res.data
          } else {
            this.$message.error(res.msg) // + res.message
          }
        })
      },
      getData () {
        busPrintSettingsOne().then((res) => {
          if (res.code === 200) {
            this.form = res.data
          } else {
            this.$message.error('查詢失敗')//  + res.message
          }
        })
      },
      handleSubmit () {
        this.$print(this.$refs.print) // 使用
        this.handleCancel()
      },
      handleCancel () {
        this.visible = false
        this.data = {}
      }
    }
  }
</script>
<style scoped>
.print{
  padding: 6px 10px;
}
.title{
  text-align: center;
  tab-size: 20px;
}
.item-end{
  float: right;
}
.main-content{
  margin-top: 10px;
  margin-bottom: 10px;
  border: solid 1px rgb(218, 211, 211);
}
.dj{
  border-bottom: solid 1px rgb(218, 211, 211);
}
.main-content-item{
  padding: 10px;
}
</style>
